<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/7/24
 * Time: 15:07
 */
namespace common\components\services\restclient;

use common\components\helpers\Fun;
use common\components\helpers\Util;
use yii\helpers\Html;
use yii\web\NotFoundHttpException;

class BackRest extends BaseRest
{
    //public static url() = 'http://www.doumiaoduo.net/index.php?r=api/';

    protected static function url()
    {
        return \Yii::$app->params['http_system_api_rest_api'];
    }

    public static function listSite()
    {
        $url = self::url() . 'site';
        return BaseRest::httpGet($url);
    }

    public static function listVirtualCard()
    {
        $url = self::url() . 'virtual';
        return BaseRest::httpGet($url);
    }

    public static function listBatch()
    {
        $url = self::url() . 'batch/index';
        return BaseRest::httpGet($url);
    }

    public static function listCardAttr()
    {
        $url = self::url() . 'cardattr';
        return BaseRest::httpGet($url);
    }

    public static function findCardAttrByBatchId($param)
    {
        $url = self::url() . 'cardattr/packetcard&param=' . $param;
        return BaseRest::httpGet($url);
    }

    public static function listTags()
    {
        $url = self::url() . 'tags';
        return BaseRest::httpGet($url);
    }

    public static function listSetting()
    {
        $url = self::url() . 'setting/index';
        return BaseRest::httpGet($url);
    }

    public static function updatePacket($data)
    {
        $url = self::url() . 'packet/update';
        return BaseRest::httpPut($url, $data);
    }

    public static function updateBatch($data)
    {
        $url = self::url() . 'batch/update';
        return BaseRest::httpPut($url, $data);
    }

    public static function createCustomer($data)
    {
        $url = self::url() . 'customer/create';
        return BaseRest::httpPost($url, $data);
    }

    public static function updateCustomer($data)
    {
        $url = self::url() . 'customer/update';
        return BaseRest::httpPut($url, $data);
    }

    public static function deleteCustomer($data)
    {
        $url = self::url() . 'customer/delete';
        return BaseRest::httpDelete($url, $data);
    }

    public static function createPta($data)
    {
        $url = self::url() . 'pta/create';
        return BaseRest::httpPost($url, $data);
    }

    public static function updateCardAttr($data)
    {
        $url = self::url() . 'cardattr/update';
        return BaseRest::httpPut($url, $data);
    }

    public static function createLoginAuth($data)
    {
        $url = self::url() . 'loginauth/create';
        return BaseRest::httpPost($url, $data);
    }

    public static function createWexinAuth($data)
    {
        $url = self::url() . 'wexinauth/create';
        return BaseRest::httpPost($url, $data);
    }

    public static function viewCardAttr($param)
    {
        $url = self::url() . 'cardattr/view&param=' . $param;
        return BaseRest::httpGet($url);
    }

    public static function checkCardAttr($param)
    {
        $url = self::url() . 'cardattr/check&param=' . $param;
        return BaseRest::httpGet($url);
    }

    public static function updateMessage($data)
    {
        $url = self::url() . 'message/update';
        return BaseRest::httpPut($url,$data);
    }

    /*public static function SquareRest($city_id, $modelClass)
    {
        $square = BackRest::BackstageRest('site');
        $website_data = Fun::cache('website_cache');
        $data_arr = [];
        foreach ($website_data as $wkey =>$wval) {
            foreach ($square as $skey => $sval) {
                if ($city_id == $wval['id']) {
                    if ($city_id == $sval['web_site_id']) {
                        $data_arr[$wval['name']][$sval['domain']] = $sval;
                        $data_arr[$wval['name']][$sval['domain']]['square_url'] = $sval['domain'] . self::$squareUrl . '-' . $modelClass . '-index';
                        $data_arr[$wval['name']][$sval['domain']]['data'] = BaseRest::httpGet($sval['domain'] . self::$squareUrl . '-' . $modelClass . '-index');
                    }
                }
            }
        }
        return $data_arr;
    }

    public static function BackstageRest($modelClass)
    {
        $url = self::$backstageUrl . $modelClass . '/index';
        if (BaseRest::httpGet($url) == null) {
            throw new NotFoundHttpException(\Yii::t('backend', '数据不存在'));
        }
        return BaseRest::httpGet($url);
    }*/

}